<template>
	<view>
		<uni-section title="">
			<uni-search-bar @confirm="search" confirm-type="search" :focus="true" @clear="clear" @cancel="clear"
				v-model="queryParams.taskName" />
		</uni-section>
		<view class="container">
			<up-down-load :callback="getList" :top="157">
				<view v-for="(item, index) in list" :key="index">
					<uni-card :title="item.name" type="line" @click="handleToDetail(item)">
						<uni-row class="font-9">
							流程定义名称：{{item.processDefinitionName}}
						</uni-row>
						<uni-row class="font-9">
							任务名称：{{item.name}}
						</uni-row>
						<uni-row class="font-9">
							办理人：{{item.assignee}}
						</uni-row>
					</uni-card>
				</view>
			</up-down-load>
		</view>
	</view>
</template>

<script>
	import taskApi from "@/api/workflow/task.js";

	import upDownLoad from '@/components/up-down-load/up-down-load.vue'
	export default {
		components: {
			upDownLoad
		},
		data() {
			return {
				mescroll: null, //保存该分页组件的mescroll对象
				list: [],
				total: 0,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					taskName: '',
					processDefinitionKey: ''
				},
			}
		},
		onLoad: function(option) {
			this.queryParams.processDefinitionKey = option.processDefinitionKey
		},
		methods: {
			getList(mescroll) {
				this.mescroll = mescroll;
				//页码
				this.queryParams.pageNum = mescroll.num;
				//每页数量
				this.queryParams.pageSize = mescroll.size;
				taskApi.getTaskWaitByPage(this.queryParams).then(res => {
					if (res.rows === null) {
						res.rows = []
					}
					//获取后端返回当前页码的数据
					let list = res.rows;
					//存储后端返回的数据总数
					this.total = res.total;
					//如果当前是第一页则置空数据
					if (mescroll.num == 1) this.list = [];
					//使用concat方法拼接数据
					this.list = this.list.concat(list);
					//使用concat方法拼接数据
					//调用endBySize方法,当数据长度为总数的时候结束分页
					mescroll.endBySize(list.length, this.total);
				})
			},
			//检索
			search() {
				this.queryParams.pageNum = 1
				this.list = []
				this.getList(this.mescroll)
			},
			//清空
			clear() {
				this.queryParams = {}
				this.queryParams.pageNum = 1
				this.queryParams.pageSize = 1
				this.list = []
				this.getList(this.mescroll)
			},
			//请假详情
			handleToDetail(data) {
				this.$tab.navigateTo(
					`/pages/demo/leave/leave?businessKey=${data.businessKey}&taskId=${data.id}&processDefinitionKey=${this.queryParams.processDefinitionKey}`
				)
			}
		}
	}
</script>
</style>
